package com.shundr.auth.activity;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;

import com.shundr.auth.R;
import com.shundr.auth.base.BaseActivity;
import com.shundr.auth.common.view.DialogAuth;
import com.shundr.auth.frame.constant.LContext;
import com.shundr.auth.frame.http.LHttpRequest;
import com.shundr.auth.frame.util.StringUtil;
import com.shundr.auth.frame.util.ToastHelper;
import com.shundr.auth.user.http.UserRequest;
import com.shundr.auth.user.model.UserInfo;

public class BindUserActivity extends BaseActivity {
	private EditText etPhone;
	private Button btnBind;
	private RadioGroup rgLvl;
	
	private int usrLvl = 0; // 0-普通， 1-优质

	private Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case UserRequest.BIND_USER_SUCCESSED:
//				new UserRequest(mContext, mHandler).makeUserQuality(etPhone.getText().toString(), usrLvl);
				etPhone.setText("");
				ToastHelper.toastLong(mContext, msg.obj.toString());
				break;

			case LHttpRequest.REQUEST_FAILED:
				ToastHelper.toastLong(mContext, msg.obj.toString());
				break;

			default:
				break;
			}
			super.handleMessage(msg);
		}

	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_bind_user);
		etPhone = (EditText) findViewById(R.id.et_user_phone);
		rgLvl = (RadioGroup) findViewById(R.id.rg_lvl);

		btnBind = (Button) findViewById(R.id.btn_bind);
		btnBind.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (check()) {
					new UserRequest(mContext, mHandler).bindUserConfirm(etPhone
							.getText().toString().trim());
				}
			}
		});
		
		rgLvl.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.rbtn_1:
					usrLvl = 1;
					break;
					
				case R.id.rbtn_2:
					usrLvl = 0;
					break;

				default:
					break;
				}
				
			}
		});
	}

	private boolean check() {
		if (StringUtil.isNull(etPhone.getText().toString())) {
			ToastHelper.toastShort(mContext, "请输入手机号");
			return false;
		}
		return true;
	}

}
